var server_url = require('../constants/server_url');
import { find_inurl, find_outurl, email_url_list } from './api'

async function getRouter(ctx, next) {
    switch (ctx.path) {
        case server_url.in_url_add:
            ctx.render('in_url_editor');
            break;
        case server_url.out_url_add:
            ctx.render('out_url_editor');
            break;
        case server_url.in_url_list:
            let list = await find_inurl();
            ctx.render('in_url_list', {list: list});
            break;
        case server_url.in_url_list_avail:
            list = await find_inurl({status:1});
            ctx.render('in_url_list', {list: list});
            break;
        case server_url.in_url_edit(ctx.params.id)[1]:
            let item = await find_inurl({_id: ctx.params.id});
            ctx.render('in_url_editor', {item: item[0]});
            break;
        case server_url.out_url_list:
            list = await find_outurl();
            ctx.render('out_url_list', {list: list});
            break;
        case server_url.out_url_list_avail:
            list = await find_outurl({status:1});
            ctx.render('out_url_list', {list: list});
            break;
        case server_url.out_url_edit(ctx.params.id)[1]:
            item = await find_outurl({_id: ctx.params.id});
            ctx.render('out_url_editor', {item: item[0]});
            break;
        case server_url.email_url_list:
            list = await email_url_list();
            ctx.render('email_url_list', {list: list});
            break;
        case server_url.email_url_list_0:
            list = await email_url_list({status:0});
            ctx.render('email_url_list', {list: list});
            break;
        case server_url.email_url_list_1:
            list = await email_url_list({status:1, createTime:{$lt:Date.now()-7*24*60*60*1000}});
            ctx.render('email_url_list', {list: list});
            break;
        case server_url.email_url_list_2:
            list = await email_url_list({status:2, createTime:{$lt:Date.now()-7*24*60*60*1000}});
            ctx.render('email_url_list', {list: list});
            break;
    }
}


module.exports=getRouter;